package nk.greedy;

import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;
import java.util.TreeSet;

public class Ab31_2 {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);

        int n = in.nextInt();

        int[][] time = new int[n][2];

        for (int i = 0; i < n; i++) {
            time[i][0] = in.nextInt();
            time[i][1] = in.nextInt();
        }
        Arrays.sort(time, new Comparator<int[]>() {
            @Override
            public int compare(int[] o1, int[] o2) {
                if (o1[1] == o2[1])
                    return o1[0] - o2[0];
                return o1[1] - o2[1];
            }
        });

        int endTime = time[0][1];
        int ans = 1;
        for (int i = 1; i < n; i++) {
            if (endTime <= time[i][0]) {
                ans++;
                endTime = time[i][1];
            }
        }
        System.out.println(ans);
    }



}
